﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SpriteObjects
{
    class My2DSprite
    {
        private float _normalDelay = 16.0f;

        public float NormalDelay
        {
            get { return _normalDelay; }
            set { _normalDelay = value; }
        }

        private Texture2D[] _Textures;

        public Texture2D[] Textures
        {
            get { return _Textures; }
            set {
                _Textures = value;
                _nTexture = _Textures.Length;
                _iTexture = 0;
            }
        }

        private Vector2 _Pos;

        public Vector2 Pos
        {
            get { return _Pos; }
            set { _Pos = value; }
        }

        private int _iTexture;

        public int iTexture
        {
            get { return _iTexture; }
            set { _iTexture = value; }
        }

        private int _nTexture;

        public int nTexture
        {
            get { return _nTexture; }
            set { _nTexture = value; }
        }


        public My2DSprite(Texture2D[] textures, Vector2 pos)
        {
            Textures = textures;
            Pos = pos;
        }


        public void Update(GameTime gameTime)
        {
            int delta = (int)(gameTime.TotalGameTime.TotalMilliseconds / _normalDelay);
            _iTexture = delta % _nTexture;

        }

        public void UpdateNextTexture(GameTime gameTime)
        {
            _iTexture = (++_iTexture) % _nTexture;

        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(_Textures[_iTexture], _Pos, Color.White);
        }

        public bool IsClicked(Vector2 vector)
        {
            Rectangle reg = new Rectangle((int)_Pos.X, (int)_Pos.Y, _Textures[0].Width, _Textures[0].Height);
            return reg.Contains((int)vector.X, (int)vector.Y);
        }
    }
}
